package binarytreedemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2024-01-23
 * Time: 17:23
 */
public class Main {

    public static void main(String[] args) {
        //实例化二叉树
        BinaryTree binaryTree = new BinaryTree();
        //通过生成一个根结点，来实现生成整棵树(createTree的类型是TreeNode)
        BinaryTree.TreeNode root = binaryTree.createTree();
        System.out.println("前序遍历");
        binaryTree.preOrder(root);
        System.out.println();
        System.out.println("中序遍历");
        binaryTree.inOrder(root);
        System.out.println();
        System.out.println("后序遍历");
        binaryTree.postOrder(root);
        System.out.println();
        System.out.println("size:" + binaryTree.size(root));
        System.out.println("叶子节点个数为:");
        System.out.println(binaryTree.getLeafNodeCount2(root));
        System.out.println("第3层的叶子节点个数:");
        System.out.println(binaryTree.getKLevelNodeCount(root,3));
        System.out.println("二叉树高度:");
        System.out.println(binaryTree.getHeight(root));
        System.out.println("查找结点:");
        //如果这里返回的是null， 下方调用时会产生空指针异常（利用try-catch解决）
        BinaryTree.TreeNode findNode = binaryTree.find(root,'G');
        System.out.println(findNode.val);
        System.out.println("层次遍历");
        binaryTree.levelOrder(root);
        //判断是否为完全二叉树:
        System.out.println();
        System.out.print("判断是否为完全二叉树:");
        System.out.println(binaryTree.completeTree(root));
    }
}
